package service

import (
	"order_srv/global"
	"order_srv/internal/model"
)

func FindProductInfo() model.SysProduct {

	var product model.SysProduct
	global.DB.Find(&product)
	return product

}
func GetAllProductInfo() ([]model.SysProduct, error) {
	var product []model.SysProduct
	err := global.DB.Where("num BETWEEN  ? AND ?", 0, 0).Find(&product).Error
	if err != nil {
		return nil, err
	}
	return product, nil
}

func GetAllOrder(userID int) []model.SysOrder {
	var order []model.SysOrder
	err := global.DB.Where("user_id = ?", userID).Find(&order).Error
	if err != nil {
		return nil
	}
	return order
}

func GetDetailOrder(orderId, userID int) model.SysOrder {
	var order model.SysOrder
	err := global.DB.Where("id  = ? AND user_id = ?", orderId, userID).Find(&order).Error
	if err != nil {
		return model.SysOrder{}
	}
	return order
}
func GetCouponPrice(couponId int, userId int) model.SysCoupon {
	var coupon model.SysCoupon
	global.DB.Where("id = ? AND user_id = ?", couponId, userId).First(&coupon)
	return coupon
}
func GetProductDetail(ProductId int) model.SysProduct {
	var product model.SysProduct
	err := global.DB.Where("id = ?", ProductId).First(&product).Error
	if err != nil {
		return model.SysProduct{}
	}
	return product
}
